import http from "@/http/request";

export const getInterviewOld: any = () => {
    return http.request({
        url: '/interview/active',
        method: 'get'
    })
}

export const getInterviewMessages: any = (id: number)=>{
    return http.request({
        url: `/interview/${id}/messages`,
        method: 'get'
    })
}
// 根据ID查询面试信息
export const getInterviewById: any = (id: number) => {
    return http.request({
        url: `/interview/${id}`,
        method: 'get'
    })
}

export const createInterview: any = (data: any) => {
    return http.request({
        url: '/interview/create',
        data: data,
        method: 'post'
    })
}



// 获取面试列表
export const getInterviewList: any = (data: any)=>{
    return http.request({
        url: '/interview/list',
        data: data,
        method: 'post'
    })
}
// 获取面试评分
export const getInterviewScore: any = (id : any)=>{
    return http.request({
        url: `/interview/score`,
        data: {
            interviewId: id,
            forceRegenerate : false
        },
        method: 'post'
    })
}

export const pushAIMessage: any = (id: number, content: any) => {
    return http.request({
        url: '/interview/save-ai-message',
        data: {
            interviewId: id,
            content: content
        },
        method: 'post'
    })
}

export const receiveAIMessage: any = (
    data: any,
    onMessage: (chunk: string) => void,
    onError: (error: any) => void,
    onComplete?: () => void // 新增 onComplete 回调
) => {
    return http.streamRequest(
        '/interview/send-message-stream',
        data,
        onMessage,
        onError,
        onComplete // 传递 onComplete 回调
    );
}

export const receiveAIMessageAgain: any = (
    data: any,
    onMessage: (chunk: string) => void,
    onError: (error: any) => void,
    onComplete?: () => void // 新增 onComplete 回调
) => {
    return http.streamRequest(
        '/interview/send-reflection-message-stream',
        data,
        onMessage,
        onError,
        onComplete // 传递 onComplete 回调
    );
}

export const finishInterview: any = (id: number) => {
    return http.request({
        url: `/interview/end/${id}`,
        method: 'post'
    })
}

export const getRequirement: any = (company: string, position: string) => {
    return http.request({
        url: '/interview/generate-job-requirement',
        method: 'post',
        data:{
            company: company,
            position: position
        }
    })
}

export const postAudioUrl: any = (data: any)=>{
    return http.request({
        url: `/interview/update-message`,
        method: 'put',
        data: data
    })
}

export const getInterviewEvaluation: any = (id: number) => {
    return http.request({
        url: `/interview/evaluation`,
        data: {
            interviewId: id,
            forceRegenerate: false
        },
        method: 'post'
    })
}

export const getImprovementPlan: any = (id: number) => {
    return http.request({
        url: `/interview/improvement-plan`,
        data: {
            interviewId: id,
            planCount: 4,
            forceRegenerate: false
        },
        method: 'post'
    })
}